package com.cn.dao.impl;

import java.util.List;

import org.hibernate.Query;

import com.cn.dao.CityDAO;

public class CityDAOImpl extends  BaseHibernateDAOImpl implements CityDAO{
	
	public List<Object> findByPId(String provinceId){
		try {
			String hql = "from City as city where city.province.id ="+provinceId;
			getSession().beginTransaction();
			Query queryObject = getSession().createQuery(hql);
			//queryObject.setString("provinceID",provinceId);
			List<Object> list = queryObject.list();
			getSession().getTransaction().commit();
			return list;
		} catch (RuntimeException re) {
			throw re;
		}
	
	}
	
	/**
	 * 根据cityID查找城市对象
	 * @param cityID
	 * @return
	 */
	public Object findById(int cityID) {
		try {
			String queryString = "from City as city where id  =" + cityID ;
			getSession().beginTransaction();
			Query queryObject = getSession().createQuery(queryString);
			List list = queryObject.list();
			getSession().getTransaction().commit();
			if (list.size() == 0) {
				return null;
			}
			return list.get(0);
		} catch (RuntimeException re) {
			throw re;
		}
	}
}
